<include file="header" />
<div class="wraper">
    <div class="load">
        <img class="load-bee" src="/assets/base/laundry/images/load-bee.png">

    </div>
    <div class="head clearfix">
        <a href="javascript:history.back();" class="iconfont icon-zuo pull-left"></a>
        <span class="head-name pull-left">{BEESCRM:$app_name}</span>
        <a href="{BEESCRM::U('/Base/laundry/index',array('laundryId'=>$laundryId))}" class="iconfont icon-shouye pull-left text-right"></a>
    </div>
    <!--<p class="margin-top lists">你的充值余额为：<span class="price">{BEESCRM:$user['amount']}</span></p>-->
    <div class="block-space text-center">
        <div class="iconfont icon-shijian time"></div>
        时长余额：<span>{BEESCRM:$userInfo['overplus_time']}	</span>
    </div>
    <div class="contain-box">
        <p class="limit-time">请选择 <span>预冻结洗衣时长<span class="iconfont icon-tanhao"></span></span></p>
        <div class="tab-prize clearfix">
            <volist name="exchangeList" id="vo">
                <span class="option sub-list <if condition="$key eq 1">checked</if>" data-amount="{BEESCRM:$vo.value}">{BEESCRM:$vo.value}分钟</span>
            </volist>

            <!--<span class="option sub-list" data-amount="80">80分钟</span>
            <span class="option sub-list" data-amount="100">100分钟</span>-->
            <p class="option other"><input placeholder="其他" id="freezing_time"/></p>
        </div>
    </div>
    <!-- <div class="tariff">
        <p>说明：</p>
        <p>预冻结时长即用于本次洗衣的最大时长，如果您在洗衣结束时忘记点击结束按钮，系统会在预冻结时长消耗完时结束本次洗衣；若预冻结时长有剩余，会在本次洗衣完成时返还您的账户。</p>
    </div> -->
    <div class="tariff">
        <span class="tariff-tag">收费标准</span>
        <if condition="$memo">
            <p>{BEESCRM:$memo}</p>
            <else/>
            <p>充值1元洗衣{BEESCRM:$preTime}分钟，账户余额以分钟显示。</p>
        </if>
    </div>
    <div class="btn-box">
        <a href="javascript:void(0)" id="do_wash_container" class="btn submit">开始洗衣</a>
    </div>
    <div class="bottom-box">
        <p class="copyright">杭州青橄榄网络技术有限公司 技术支持</p>
    </div>
    <input type="hidden" id="terminal_id" value="{BEESCRM:$terminalInfo.terminal_id}">
    <input type="hidden" id="website_id" value="{BEESCRM:$terminalInfo.website_id}">
    <input type="hidden" id="overplus_time" value="{BEESCRM:$userInfo['overplus_time']}">
    <input type="hidden" id="fees" value="{BEESCRM:$terminalInfo.fees}">
    <input type="hidden" id="subscribe" value="{BEESCRM:$subscribe}">
</div>
<div class="pop-box">
    <div class="main">
        <p>长按下面二维码</p>
        <p>关注<span class="text-yellow">【{BEESCRM:$laundry.qrcode_name}】</span></p>
        <img src="{BEESCRM:$laundry.qrcode}"/>
    </div>
</div>
<div class="pop-box guanbi" style="display: block">
    <div class="box-main">
        <p class="iconfont icon-guanbi text-right"></p>
        <p class="iconfont icon-gongnengshuoming"></p>
        <p class="title">预冻结时长说明</p>
        <p class="text">【预冻结时长】即用于本次洗衣的最大时长，如果您在洗衣结束时，忘记点击结束按钮，系统会在预冻结时长消耗完时结束本次洗衣；</p>
        <p class="text">若预冻结时长有剩余，会在本次洗衣完成时返还您的账户</p>
    </div>
</div>

<script src="/assets/base/repair/js/jquery-2.1.0.min.js"></script>
<script src="/assets/base/repair/js/jq.utils.js"></script>
<script src="/assets/base/repair/js/sweetalert/lib/sweet-alert.min.js"></script>
<script>
    var height = $(document).height();
    var bottombox_height = $('.bottom-box').outerHeight();
    $('.wraper').css("minHeight",height);
    $('.wraper').css("paddingBottom",bottombox_height);

    $(window).load(function(){
        $('.load').hide();
    });
    $('.classify-box').on('click','.classify-list',function(){
        $(this).addClass('choosed').siblings().removeClass('choosed');
    });

    $(function(){
        $(document).on('click','#do_wash_container',function(){
            var freeReg = /^[0-9]*[1-9][0-9]*$/;
            var json={};
            var data={};
            var overplus_time=Number($('#overplus_time').val());
            var fees=$('#fees').val();
            data.fees=fees;
            data.terminal_id=$('#terminal_id').val();
            data.website_id=$('#website_id').val();
            var freezing_time=Number($('#freezing_time').val());
            if(!freezing_time){
                data.value=Number($('.checked').data('amount'));
                if(!data.value){
                    $.alert('error','请选择洗衣时长');return false;
                }
            }else{
                if(!freeReg.test(freezing_time)){
                    $.alert('error','洗衣时长只能为正整数');return false;
                }else{
                    data.value=freezing_time;
                }
            }
            if(data.value>overplus_time && fees==0){
                $.alert('error','无法洗衣，时长余额不足');return;
            }
            if(!data.terminal_id || !data.website_id){
                $.alert('error','参数错误');return;
            }

            json.data=data;
            json.url="{BEESCRM::U('/base/Laundry/washAjax',array('laundryId'=>$laundryId))}";
            json.method='post';
            json.type='json';
//			$.getAjax(json,true,function(res){
//				reload(res.id)
//			});

            $.ajax({
                url: json.url,
                method: json.method,
                data: json.data,
                beforeSend: function () {
                    $('.scrm-loadding').show();
                },
                success: function(res) {
                    $('.scrm-loadding').hide();

                    var msg = $.parseJSON(res);
                    $.alert("success", msg.message);
                    reload(msg.id);
                },
                error: function(err) {
                    $('.scrm-loadding').hide();

                    $.alert('error', JSON.stringify(err));
                }
            });
        });

        //刷新页面
        function reload(id){
            var url = "{BEESCRM::U('/base/laundry/washing',array('laundryId'=>$laundryId))}"+'/id/'+id;
            setTimeout('location.href="'+url+'"', 3000);
        }

        $('.icon-guanbi').click(function(){
            $('.guanbi').hide();
        });

        $('.tab-prize').on('click','.option',function(){
            if($(this).hasClass('other')){
                $(this).siblings().removeClass('checked');
                $('#amount').change(function(){
                    var num=Number($(this).val());
                    if(num!=0){
                        $('#hour').text(num);
                        $('#minute').val(num*60);
                    }
                })

            }
            else{
                if(!$(this).hasClass('checked')){
                    $(this).toggleClass('checked').siblings().removeClass('checked');
                }
                $('#amount').val(0);
                var num=Number($(this).data('amount'));
                $('#hour').text(num);
                $('#minute').val(num*60);

            }
        })

    });

    $('.tab-prize').on('click','.option',function(){
        if($(this).hasClass('other')){
            $(this).addClass('checked').siblings().removeClass('checked');
            $('#freezing_time').val('');
        }
        else{
            $(this).toggleClass('checked').siblings().removeClass('checked');
            $('#freezing_time').val('');
        }
    });
</script>
</body>
</html>